'use strict';
const moment = require('moment');

//收益历史
module.exports = app => {
    const {
        DATE,
        INTEGER,
        FLOAT,DECIMAL
    } = app.Sequelize;
    const WithdrawHistory = app.model.define('withdrawHistory', {
        id: {
            primaryKey: true,
            type: INTEGER,
            autoIncrement: true
        },
        userId: {//用户id
            type: INTEGER,
            allowNull: false
        }, 
        money: {//多少分
            type:DECIMAL(5,2),// FLOAT(5,2),  
            allowNull: false,
            defaultValue: 0.00, 
        }, 
        paytype: {//付到用户什么帐户类型上  
            type: INTEGER(1).UNSIGNED,
            allowNull: true
        }, 
        historyType: {
            type: INTEGER(1).UNSIGNED, //0: 是提现  1: 分成  2: 打卡收益  
            allowNull: false
        },        
    }, {
        freezeTableName: true, // Model 对应的表名将与model名相同
        timestamps: true, //自动添加createdAt、updatedAt两个字段，分别表示创建和更新时间,且时间是实际时间,表里显示的是2019-02-13 23:50:20
        paranoid: true,//假删除
            underscored: false,////不要改此   false: 字段以下划线（_）来分割（默认是驼峰命名风格）
            charset: 'utf8',
        collate: 'utf8_general_ci',
    });
     WithdrawHistory.associate = () => {
            // console.log("--------------====")
           app.model.WithdrawHistory.belongsTo(app.model.User, {
              as: 'user',
              onDelete: 'CASCADE',
            foreignKey: 'userId', //此userId 与 user表的 id  是对应的
            })
          } //*/
    return WithdrawHistory;
};